package com.example.lenovo.firstjob;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

/**
 * Created by Lenovo on 2018/9/13.
 */
public class ThirdActivity extends Activity implements View.OnClickListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.third_layout);

        Button button = (Button) findViewById(R.id.back);
        button.setOnClickListener(this);


    }

    public static void startAction(Context context,String data) {
        Intent intent = new Intent(context,ThirdActivity.class);
        intent.putExtra("data",data);
        context.startActivity(intent);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        ImageView imageView = (ImageView) findViewById(R.id.image);

        imageView.setDrawingCacheEnabled(Boolean.TRUE);
        intent.putExtra("BITMAP", imageView.getDrawingCache());
        Toast.makeText(this,"image",Toast.LENGTH_SHORT).show();

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tt);

//        Bitmap bitmap = BitmapFactory.decodeResource(this.getContext().getResources(), imageView);
//        intent.putExtra("image",bitmapToByte(bitmap));
        finish();
    }

    private byte[] bitmapToByte(Bitmap bitmap) {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG,100,byteArrayOutputStream);
        return byteArrayOutputStream.toByteArray();
    }
}


//http://blog.sina.com.cn/s/blog_8996e7110102wkl2.html
// https://www.jb51.net/article/106820.htm
// https://www.aliyun.com/jiaocheng/59367.html

//https://blog.csdn.net/u011254881/article/details/53128199